<template>
  <div class="dashboard-editor-container">

    <div class="tips-header">

      <el-avatar :size="72" :src="user.avatar" fit="scale-down"></el-avatar>
      <div class="tips-right">
        <p class="info-group">
          <span>{{title}}</span>
          <span>{{user.name}}</span>
        </p>
        <div class="shici text-info text-small">
          <div>{{shici.content}}</div>
          <footer>—{{shici.origin.author}}<cite><<{{shici.origin.title}}>></cite></footer>
        </div>
      </div>
    </div>

    <panel-group @handleSetLineChartData="handleSetLineChartData"/>

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <!--      <line-chart :chart-data="lineChartData"/>-->

      <ve-line :data="chartData"></ve-line>

    </el-row>

    <el-row :gutter="32">
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <ve-histogram :data="dailyMoCountPriceData"
                        :settings="{ showLine: ['price'],labelMap: {count: '就诊人数',price: '收入'}}"></ve-histogram>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart/>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <bar-chart/>
        </div>
      </el-col>
    </el-row>


  </div>
</template>

<script>
  import PanelGroup from './dashboard/PanelGroup'
  import LineChart from './dashboard/LineChart'
  import RaddarChart from './dashboard/RaddarChart'
  import PieChart from './dashboard/PieChart'
  import BarChart from './dashboard/BarChart'
  import { getDailyCountPrice } from '../api/analysis/medicalOrder'

  const jinrishici = require('jinrishici')

  const lineChartData = {
    newVisitis: {
      expectedData: [100, 120, 161, 134, 105, 160, 165],
      actualData: [120, 82, 91, 154, 162, 140, 145]
    },
    messages: {
      expectedData: [200, 192, 120, 144, 160, 130, 140],
      actualData: [180, 160, 151, 106, 145, 150, 130]
    },
    purchases: {
      expectedData: [80, 100, 121, 104, 105, 90, 100],
      actualData: [120, 90, 100, 138, 142, 130, 130]
    },
    shoppings: {
      expectedData: [130, 140, 141, 142, 145, 150, 160],
      actualData: [120, 82, 91, 154, 162, 140, 130]
    }
  }

  export default {
    name: 'Index',
    components: {
      PanelGroup,
      LineChart,
      RaddarChart,
      PieChart,
      BarChart
    },
    data() {
      return {
        lineChartData: lineChartData.newVisitis,
        user: {},
        title: '',
        shici: {
          origin: {
            author: '杨'
          }
        },
        weather: {},
        chartData: {
          columns: ['date', 'PV'],
          rows: [
            { 'date': '1/1', 'PV': 1393 },
            { 'date': '1/2', 'PV': 3530 },
            { 'date': '1/3', 'PV': 2923 },
            { 'date': '1/4', 'PV': 1723 },
            { 'date': '1/5', 'PV': 3792 }
          ]
        },
        dailyMoCountPriceData: {
          columns: ['date', 'count', 'price'],
          rows:[]
        }
      }
    },

    methods: {
      handleSetLineChartData(type) {
        this.lineChartData = lineChartData[type]
      },

      getNowTitle() {
        const date = new Date()
        const hours = date.getHours()
        if (hours > 6 && hours < 12) {
          this.title = '早上好!'
        } else if (hours >= 12 && hours < 14) {
          this.title = '中午好!'
          console.log(111)
        } else if (hours >= 14 && hours < 18) {
          this.title = '下午好!'
        } else if (hours >= 18 && hours < 23) {
          this.title = '晚上好!'
        } else {
          this.title = '夜深了!'
        }
      }

    },
    async created() {
      this.user = this.$store.state.user
      this.getNowTitle()
      jinrishici.load(res => {
        this.shici = res.data
      })

      this.dailyMoCountPriceData.rows = (await getDailyCountPrice()).data

    }
  }


</script>

<style lang="scss" scoped>

  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }

  .tips-header {
    display: flex;
    justify-content: space-around;
    align-items: center;
  }

  .tips-right {
    display: flex;
    flex-direction: column;
  }

  .info-group {
    font-size: 20px;
  }

  .shici {
    display: flex;
    flex-direction: column;

  }

  footer {
    align-self: flex-end;
    font-size: 10px;
    margin-top: 10px;
  }

  .name {
    font-size: 30px;
    color: #409EFF

  }

  @media (max-width: 1024px) {
    .chart-wrapper {
      padding: 8px;
      margin-bottom: 15px !important;
    }
  }
</style>
